package ar.com.osdepym.agregacionafip.adapters;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import ar.com.osdepym.agregacionafip.activities.R;

public class ABMListAdapter extends ArrayAdapter<Contenedor>{


    Context context; 
    int layoutResourceId;    
    List<Contenedor> data = null;
    private OnClickListener buttonHandler;
    
    public ABMListAdapter(Context context, int layoutResourceId, List<Contenedor> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }
    
    public OnClickListener getButtonHandler() {
		return buttonHandler;
	}

	public void setButtonHandler(OnClickListener buttonHandler) {
		this.buttonHandler = buttonHandler;
	}

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ContenedorHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new ContenedorHolder();
            holder.txtTitle = (TextView)row.findViewById(R.id.itemText);
            holder.button = (Button)row.findViewById(R.id.delete_item);
            holder.button.setOnClickListener(buttonHandler);
            
            row.setTag(holder);
        }
        else
        {
            holder = (ContenedorHolder)row.getTag();
        }
        
        Contenedor Contenedor = data.get(position);
        holder.txtTitle.setText(Contenedor.getNombre());
        
        return row;
    }
    
    static class ContenedorHolder
    {
        TextView txtTitle;
        Button button;
    }
}


